<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>01-非受控组件</title>
  </head>
  <body>
    <div id="app"></div>

    <!-- 导入 react 主库 -->
    <script src="../js/react.development.js"></script>
    <!-- 导入 reactDom 扩展库 -->
    <script src="../js/react-dom.development.js"></script>
    <!-- 导入 babel 用于将jsx转为js -->
    <script src="../js/babel.min.js"></script>
    <!-- 导入 prop-types 用于对组件标签属性进行限制 -->
    <script src="../js//prop-types.js"></script>

    <script type="text/babel">
      // 定义类组件
      class Login extends React.Component {

        handlerSubmit = (event) => {
            console.log(event);  // 这种方法可以拿到当前事件绑定的dom元素
            event.preventDefault()  // 阻止表单的默认提交   
            const {username, password} = this
            alert(`用户名：${username.value}  密码：${password.value}`)
            console.log(username, password);
        }

        render() {
          return (
            <form action="http://www.try0317.com" onSubmit={this.handlerSubmit}>
              用户名：<input ref={e => this.username = e} type="text" name="username" id="" />
              密码：<input ref={e => this.password = e} type="password" name="password" id="" />
              <button>登录</button>
            </form>
          );
        }
      }
      ReactDOM.render(<Login />, document.getElementById("app"));
    </script>
  </body>
</html>
